package com.shujia.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class Code04Download {
    public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
        Configuration conf = new Configuration();
        FileSystem fileSystem = FileSystem.get(new URI("hdfs://master:9000"), conf, "root");
        // Exception in thread "main" java.io.IOException: (null) entry in command string: null chmod 0644 D:\HadoopCode\data\fff.txt
        // 需要给定Hadoop本地运行环境
        // 根据当前Hadoop版本 去https://github.com/steveloughran/winutils 下载对应的hadoop.dll 、winutils.exe文件
        // 下载以后创建目录配置环境变量 重启IDEA使其生效
        fileSystem.copyToLocalFile(new Path("/data/fff.txt"),new Path("D:\\HadoopCode\\data\\"));
        fileSystem.close();
    }
}
